
<script type="text/javascript">
$(document).ready(function($){
	//地图显示隐藏
	$('#map').click(function(){
		$('#l-map').show();
		$('#l-mapclose').show();
	})
	$('#l-mapclose').click(function(){
		$('#l-map').hide();
		$('#l-mapclose').hide();
	})
	//城市选择
	$("#chengshi").change(function(){
		    var cid = $("#chengshi").val();
		    $.ajax({
		        type:'get',
		        url:"{:U('Ershou/getErjics')}",
		        dataType:'json',
		        data:{'id':cid},
		        success:function(data){
		        	$("#diqu").empty();
		        	$("#diqu").get(0).options.add(new Option('请选择地区',888));
		            $.each(data,function(k,v){
		                $("#diqu").get(0).options.add(new Option(v['name'],v['id']));
		            });
		        }
		    });
		});
	//地区选择
	$("#diqu").change(function(){
	    var cid = $("#diqu").val();
	    $.ajax({
	        type:'get',
	        url:"{:U('Ershou/getErjics')}",
	        dataType:'json',
	        data:{'id':cid},
	        success:function(data){
	        	$("#diming").empty();
	            $.each(data,function(k,v){
	                $("#diming").get(0).options.add(new Option(v['name'],v['id']));
	            });
	        }
	    });
	});
	//动态添加图片按钮
	var i = 2;
	$("#addimg").live('click',function(){
     $("#beginimg").before('<tr ><td class="td_right">房源图片：</td><td class=""> <input type="file" name="img' +i+ '" class="input-text lh30" size="40"> <input type="button" style="height:30px;line-height:28px;width:52px;text-align:center;" class="btn input-text" id="addimg" value="添加" /></td></tr>');
         i++;
		});

	
});
</script>
   <script type="text/javascript">
      $(function(){  
        $(".list_table").colResizable({
          liveDrag:true,
          gripInnerHtml:"<div class='grip'></div>", 
          draggingClass:"dragging", 
          minWidth:30
        }); 
        
      }); 
   </script>
 <script type="text/javascript" src="__PUBLIC__/Admin/Bd/js/function.js"></script>
   <title>Document</title>
 </head>
 <body>
  <div class="container">

      
     <div id="forms" class="mt10">
        <div class="box">
          <div class="box_border">
            <div class="box_top"><b class="pl15">填写信息</b></div>
            <div class="box_center">
              <form method="post" action="{:U('Ershou/add')}" class="jqtransform" enctype="multipart/form-data">
               <table class="form_table pt15 pb15" width="100%" border="0" cellpadding="0" cellspacing="0">
                 <tr>
                  <td class="td_right">房源来源：</td>
                  <td class="">
                    <input type="radio" checked="checked" name="laiyuan" value="1"> 中介房源
                    <input type="radio" name="laiyuan" value="2"> 个人房源
                  </td>
                 </tr>
                  <tr>
                  <td class="td_right">房源地址：</td>
                  <td class=""> 
                     <span class="fl">
                        <select id="chengshi" name="chengshi" class="select" style="min-width:100px;text-align:center;"> 
                        <option value="9999"  >请选择城市</option> 
                        <?php
                        if(!empty($chengshi)){
                        foreach($chengshi as $v){
                        ?>
                        <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option> 
                        <?php }}?>
                        </select> 城市&nbsp;&nbsp;
                    </span>
                    
                      <span class="fl">
                        <select id="diqu" name="diqu" class="select" style="min-width:100px;text-align:center;"> 
                         <option value="8888">请选择地区</option> 
                        </select> 地区&nbsp;&nbsp;
                    </span>
                    
                    <span class="fl">
                        <select id="diming" name="diming" class="select" style="min-width:100px;text-align:center;"> 
                        <option value="7777">请选择地名</option> 
                        </select> 地名&nbsp;&nbsp;
                    </span>
                    
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">地图经度：</td>
                  <td class=""> 
                    <input type="text" id="lng" required value="110.410542"  name="lng"  class="input-text lh30" size="40">
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">地图纬度：</td>
                  <td class=""> 
                    <input type="text" id="lat" required value="21.199888"  name="lat"  class="input-text lh30" size="40">
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">地图标注地址：</td>
                  <td class=""> 
                    <input type="text" id="suggestId" onchange="loadmap()" name="address"  class="input-text lh30" size="40">                  <input type="button" style="height:30px;line-height:28px;" class="btn input-text" id="map" value="地图标注" />
                  </td>
                </tr>
                <tr>
                  <td class="td_right">房源编号：</td>
                  <td class=""> 
                    <input type="text" name="code" class="input-text lh30" size="40"> 如若不填，系统则自动生成如：QJWH000000000001
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">房源标题：</td>
                  <td class=""> 
                    <input type="text" name="title" class="input-text lh30" size="40">
                  </td>
                </tr>
                <tr>
                  <td class="td_right">房源朝向：</td>
                  <td class="">
                  <?php
                  if(!empty($fycx)){
                  foreach($fycx as $v){
                  ?>
                    <input type="radio" name="fycx" value="<?php echo $v['id']?>"> <?php echo $v['name']?>
                   <?php }}?>
                  </td>
                 </tr>
                  <tr>
                  <td class="td_right">房源户型：</td>
                  <td class=""> 
                     <span class="fl">
                        <select name="shi" class="select" style="width:50px;text-align:center;"> 
                        <option value="1">1</option> 
                        <option value="2">2</option> 
                        <option value="3">3</option> 
                        <option value="4">4</option> 
                        <option value="5">5</option> 
                        <option value="5">6</option> 
                        </select> 室&nbsp;&nbsp;
                    </span>
                    
                      <span class="fl">
                        <select name="ting" class="select" style="width:50px;text-align:center;"> 
                        <option value="1">1</option> 
                        <option value="2">2</option> 
                        <option value="3">3</option> 
                        <option value="4">4</option> 
                        <option value="5">5</option> 
                        </select> 厅&nbsp;&nbsp;
                    </span>
                    
                    <span class="fl">
                        <select name="wei" class="select" style="width:50px;text-align:center;"> 
                        <option value="1">1</option> 
                        <option value="2">2</option> 
                        <option value="3">3</option> 
                        <option value="4">4</option> 
                        </select> 卫&nbsp;&nbsp;
                    </span>
                    
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">配套设施：</td>
                  <td class=""> 
                  <?php
                  if(!empty($ptss)){
                  foreach($ptss as $v){
                  ?>
                    <input type="checkbox" name="ptss[]" value="<?php echo $v['id']?>"> <?php echo $v['name']?>
                   <?php }} ?>
                  </td>
                </tr>
                <tr>
                  <td class="td_right">房源特色：</td>     
                  <td class=""> 
                  <?php
                  if(!empty($fyts)){
                  foreach($fyts as $v){
                  ?>
                    <input type="checkbox" name="fyts[]" value="<?php echo $v['id']?>"> <?php echo $v['name']?>
                   <?php }} ?>
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">房源电梯：</td>
                  <td class="">
                    <input type="radio" checked="checked" name="dianti" value="1"> 有电梯
                    <input type="radio" name="dianti" value="0"> 无电梯
                  </td>
                 </tr>
                 <script type="text/javascript">
                 $(document).ready(function(){
                   $("#xiaoqu").change(function(){
                        var value = $(this).val();
                        if(value==0){
                            $("#sxiaoqu").show();
                            }
                        if(value !=0){
                            $("#sxiaoqu").hide();
                            }
                       });
                     });
                 </script>
                 <tr>
                  <td class="td_right">所属小区：</td>     
                  <td class=""> 
                     <span class="fl">
                        <select id="xiaoqu" name="xiaoqu" class="select" style="min-width:150px;text-align:center;"> 
                        <option value="0">手动输入小区</option> 
                        <?php if(!empty($xiaoqu)){ foreach($xiaoqu as $v){?>
                        <option value="<?php echo $v['id']?>"><?php echo $v['title']?></option> 
                         <?php }}?>
                        </select> 例如：选择幸福花园
                    </span>
                  </td>
                </tr>
                 <tr id="sxiaoqu">
                  <td class="td_right">手动输入小区名：</td>     
                  <td class=""> 
                     <span class="fl">
                     <input type="text" name="srxiaoqu" class="input-text lh30" size="40"> 例如：幸福花园
                    </span>
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">联系人：</td>
                  <td class=""> 
                    <input type="text" name="contacter" class="input-text lh30" size="40">
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">联系电话：</td>
                  <td class=""> 
                    <input type="text" name="iphone" class="input-text lh30" size="40">
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">房源类型：</td> 
                  <td class="">
                     <span class="fl">
                        <select name="fylx" class="select" style="width:100px;text-align:center;"> 
                        <?php
                        if(!empty($fylx)){
                        foreach($fylx as $v){
                        ?>
                        <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option> 
                         <?php }}?>
                        </select>
                    </span>
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">装修情况：</td> 
                  <td class=""> 
                     <span class="fl">
                        <select name="zxqk" class="select" style="width:100px;text-align:center;"> 
                        <?php
                        if(!empty($zxqk)){
                        foreach($zxqk as $v){
                        ?>
                        <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option> 
                         <?php }}?>
                        </select>
                    </span>
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">总价格：</td>
                  <td class=""> 
                    <input type="text" name="total" class="input-text lh30" size="15"> 例如：650000
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">建筑面积：</td>
                  <td class="">  
                    <input type="text" name="area" class="input-text lh30" size="15"> 平方米 
                  </td>
                </tr>
                 <tr>
                  <td class="td_right">房龄：</td>
                  <td class=""> 
                    <input type="text" name="age" class="input-text lh30" size="15">
                  </td>
                </tr>
                  <tr>
                  <td class="td_right">楼层：</td>
                  <td class=""> 
                    第 <input type="text" name="ceng" class="input-text lh30" size="10"> 层 / 共 <input type="text" name="zongceng" class="input-text lh30" size="10"> 层
                  </td>
                </tr>
                  <tr>
                  <td class="td_right">产权：</td> 
                  <td class="">
                     <span class="fl">
                        <select name="fycq" class="select" style="width:100px;text-align:center;"> 
                        <?php
                        if(!empty($fycq)){
                        foreach($fycq as $v){
                        ?>
                        <option value="<?php echo $v['id']?>"><?php echo $v['name']?></option> 
                         <?php }}?>
                        </select>
                    </span>
                  </td>
                </tr>
                 <tr >
                  <td class="td_right">房源图片：</td>
                  <td class=""> 
                    <div class="imgbox" >
                    
                    
                    <?php
                    for($i=1;$i<=8;$i++){
                    ?>
                    <div class="boxs" style="position:relative;">
                    <div id="imgPreview{$i}" class="ggyy" >
                    <img id="img{$i}" border=0 src="__PUBLIC__/Admin/Bd/images/head_180.jpg" width="160" height="120" />
                    </div>
                      <div class="dianji" >点击上传<input id="fimg{$i}" type="file" class="tmd" style="margin-top:-40px;" name="img{$i}" onchange='PreviewImage{$i}(this)' /></div>
                    <a id="del{$i}" href="###"  class="dels" >删除</a>
                   </div>
                  <?php }?>

                   
                   
                    </div>
                  </td>
                </tr>
                  <tr id="beginimg">
                  <td class="td_right">详细介绍：</td>
                  <td class="">
                    <textarea name="content" id="myEditor">这里输入文章详细内容</textarea>
				       <script type="text/javascript">
				     var editor = new UE.ui.Editor({initialFrameWidth:880,initialFrameHeight:520});
				     editor.render("myEditor");
				     </script>
                  </td>
                 </tr>
                 <tr>
                  <td class="td_right">房源信息状态：</td>
                  <td class="">
                    <input type="radio" checked="checked" name="status" value="1"> 通过
                    <input type="radio" name="status" value="2"> 待审
                    <input type="radio" name="status" value="3"> 拒绝
                    <input type="radio" name="status" value="0"> 删除
                    <input type="radio" name="status" value="4">已售
                  </td>
                 </tr>
                 <tr>
                   <td class="td_right">&nbsp;</td>
                   <td class="">
                     <input type="submit"  class="btn btn82 btn_save2" value="添加"> 
                    <input type="button" name="button" class="btn btn82 btn_res" value="重置"> 
                   </td>
                 </tr>
               </table>
               </form>
            </div>
          </div>
        </div>
     </div>
   </div> 



         <div id="l-map"  style="border:1px solid #aaa;margin-left:135px;width:68%; height:520px;"></div>
         <a href="#"><div id="l-mapclose"  style="border:1px solid #aaa;margin-left:135px;width:68%; height:30px;line-height:30px;">确定地图位置并关闭</div></a>
		<div id="r-result"><input  type="hidden"  name="city" class="px" id="city" size="20" value=""/> </div> 
		<script src="http://api.map.baidu.com/api?key=a258befb5804cb80bed5338c74dd1fd1&v=1.1&services=true" type="text/javascript" ></script>
		<script type="text/javascript">
		function mkurl(){
		document.getElementById('url').value = "http://api.map.baidu.com/marker?location="+document.getElementById('lat').value+","+document.getElementById('lng').value+"&title="+ encodeURIComponent(document.getElementById('title').value)+"&content="+document.getElementById('suggestId').value+"&output=html";
		}
		var map = new BMap.Map("l-map");
		     
		var myGeo = new BMap.Geocoder();  
		//map.addControl(new BMap.MapTypeControl({mapTypes: [BMAP_NORMAL_MAP,BMAP_HYBRID_MAP]}));     //2D图，卫星图
		
		//map.addControl(new BMap.MapTypeControl({anchor: BMAP_ANCHOR_TOP_LEFT}));    //左上角，默认地图控件
		
		//alert(city);
		var currentPoint ;
		var marker1;
		var marker2;
		map.enableScrollWheelZoom(); 
		//var point = new BMap.Point(116.331398,39.897445);  
		
		map.enableDragging();   
		map.enableContinuousZoom();
		map.addControl(new BMap.NavigationControl());  
		map.addControl(new BMap.ScaleControl());  
		map.addControl(new BMap.OverviewMapControl());
		
		 var point = new BMap.Point(110.410542,21.199888);//定义一个中心点坐标
		 
		doit(point);
		
		 function auto(){
		 var geolocation = new BMap.Geolocation();  
		geolocation.getCurrentPosition(function(r){  
		if(this.getStatus() == BMAP_STATUS_SUCCESS){  
		//var mk = new BMap.Marker(r.point);  
		//map.addOverlay(mk);  
		 // point = r.point;  
		//map.panTo(r.point); 
		
		var point = new BMap.Point(r.point.lng,r.point.lat);  
		marker1 = new BMap.Marker(point);        // 创建标注
		map.addOverlay(marker1);
		var opts = {
		width : 220,     // 信息窗口宽度 220-730
		height: 60,     // 信息窗口高度 60-650
		title : ""  // 信息窗口标题
		}
		var infoWindow = new BMap.InfoWindow("定位成功这是你当前的位置!,移动红点标注目标位置，你也可以直接修改上方位置,系统自动定位!", opts);  // 创建信息窗口对象
		marker1.openInfoWindow(infoWindow);      // 打开信息窗口
		doit(point);
		
		}else {  
		 
		}  
		})
		 }
		function  doit(point){
		//map.centerAndZoom(point,12);  
		//myGeo.getPoint(city, function(point){ 
		if (point) {
		//window.external.setlngandlat(point.lng,point.lat);
		//alert(point.lng + "  ddd " + point.lat);
		 document.getElementById('lat').value = point.lat;
		  document.getElementById('lng').value =point.lng;
		map.setCenter(point);
		map.centerAndZoom(point, 15);
		map.panTo(point);
		
		var cp = map.getCenter();		
		myGeo.getLocation(point, function(result){  
		if (result){
		 document.getElementById('suggestId').value = result.address;
		 mkurl();
		}			
		});	

		marker2 = new BMap.Marker(point);        // 创建标注  
		var opts = {
		width : 220,     // 信息窗口宽度 220-730
		height: 60,     // 信息窗口高度 60-650
		title : ""  // 信息窗口标题
		}
		var infoWindow = new BMap.InfoWindow("拖拽地图或红点，在地图上用红点标注您的店铺位置。", opts);  // 创建信息窗口对象
		marker2.openInfoWindow(infoWindow);      // 打开信息窗口
		
		map.addOverlay(marker2);                     // 将标注添加到地图中
		
		marker2.enableDragging();
		marker2.addEventListener("dragend", function(e){
		 document.getElementById('lat').value =e.point.lat;
		 document.getElementById('lng').value =e.point.lng;
		
		myGeo.getLocation(new BMap.Point(e.point.lng,e.point.lat), function(result){  
		if (result){
		$('suggestId').value = result.address;
		//$('city').value = result.city;
		//			alert(result.address)				
		//	window.external.setaddress(result.address);//setarrea(result.address);//
		//marker1.setPoint(chaoxidecaonima by:weiwo));        // 移动标注
		marker2.setPoint(new BMap.Point(e.point.lng,e.point.lat));     
		map.panTo(new BMap.Point(e.point.lng,e.point.lat));
		//window.external.setlngandlat(e.point.lng,e.point.lat);
		}
		
		});	
		});	
		
		map.addEventListener("dragend", function showInfo(){
		var cp = map.getCenter();		
		myGeo.getLocation(new BMap.Point(cp.lng,cp.lat), function(result){  
		if (result){
		 document.getElementById('suggestId').value = result.address;
		 document.getElementById('lat').value =cp.lat;
		   document.getElementById('lng').value =cp.lng;
		   
		//	window.external.setaddress(result.address);//setarrea(result.address);//
		//alert(point.lng + "  ddd " + point.lat);
		//marker1.setPoint(new BMap.Point(cp.lng,cp.lat));        // 移动标注
		marker2.setPoint(new BMap.Point(cp.lng,cp.lat));     
		map.panTo(new BMap.Point(cp.lng,cp.lat));
		
		//window.external.setlngandlat(cp.lng,cp.lat);
		}			
		});	
		 mkurl();
		});	
		
		map.addEventListener("dragging", function showInfo(){
		var cp = map.getCenter();
		//marker1.setPoint(new BMap.Point(cp.lng,cp.lat));        // 移动标注
		marker2.setPoint(new BMap.Point(cp.lng,cp.lat)); 
		map.panTo(new BMap.Point(cp.lng,cp.lat));
		map.centerAndZoom(marker2.getPoint(), map.getZoom());
		});	
		}
		//}, province);		
		}
		
		
		function loadmap() {
		var province =  document.getElementById('city').value;
		var city =   document.getElementById('suggestId').value ;
		// 将结果显示在地图上，并调整地图视野  
		myGeo.getPoint(city, function(point){  
		if (point) {
		//marker1.setPoint(new BMap.Point(point.lng,point.lat));        // 移动标注
		marker2.setPoint(new BMap.Point(point.lng,point.lat));  
		//window.external.setlngandlat(marker2.getPoint().lng,marker2.getPoint().lat);
		//alert(point.lng + "  ddd " + point.lat);
		 document.getElementById('lat').value =point.lat;
		   document.getElementById('lng').value =point.lng;
		map.panTo(new BMap.Point(marker2.getPoint().lng,marker2.getPoint().lat));
		map.centerAndZoom(marker2.getPoint(), map.getZoom());
		 mkurl();
		}}, province);
		} 
		function setarrea(address,city) {
		$('suggestId').value = address;
		//$('city').value=city;
		window.setTimeout(function(){
		loadmap();
		},2000);
		}
		function initarreawithpoint(lng,lat){
		window.setTimeout(function(){
		//marker1.setPoint(new BMap.Point(lng,lat));        // 移动标注
		marker2.setPoint(new BMap.Point(lng,lat));  
		//window.external.setlngandlat(lng,lat);
		map.panTo(new BMap.Point(lng,lat));
		map.centerAndZoom(marker2.getPoint(), map.getZoom());
		}, 2000);	
		}
		</script>






   
 </body>
 </html>
   <script type="text/plain" id="j_ueditorupload" style="height:5px;display:none;" ></script>
    <script>
      //实例化编辑器
      var o_ueditorupload = UE.getEditor('j_ueditorupload',
      {
        autoHeightEnabled:false
      });
      o_ueditorupload.ready(function ()
      {
     
    o_ueditorupload.hide();//隐藏编辑器
     
    //监听图片上传
    o_ueditorupload.addListener('beforeInsertImage', function (t,arg)
    {
        $("#url").val(arg[0].src);
          //alert('这是图片地址：'+arg[0].src);
    });
     
    /* 文件上传监听
     * 需要在ueditor.all.min.js文件中找到
     * d.execCommand("insertHtml",l)
     * 之后插入d.fireEvent('afterUpfile',b)
     */
        o_ueditorupload.addListener('afterUpfile', function (t, arg)
        {
          alert('这是文件地址：'+arg[0].url);
        });
      });
       
      //弹出图片上传的对话框
      function upImage()
      {
        var myImage = o_ueditorupload.getDialog("insertimage");
        myImage.open();
      }
      //弹出文件上传的对话框
      function upFiles()
      {
        var myFiles = o_ueditorupload.getDialog("attachment");
        myFiles.open();
      } 
    </script>